package Ventanas;

import Negocios.AfiliadoNegocio;
import java.sql.Date;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class VAfiliadoBusqueda extends javax.swing.JFrame {

    private AfiliadoNegocio referencia;

    public VAfiliadoBusqueda() {
        initComponents();
    }

    public void enlazar(AfiliadoNegocio referencia) {
        this.referencia = referencia;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jRadioButton8 = new javax.swing.JRadioButton();
        jRadioButton9 = new javax.swing.JRadioButton();
        jRadioButton10 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Busquedas de Afiliados");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Criterios de Búsquedas"));

        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Buscar por Id.");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setText("Buscar por Ci.");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jRadioButton3.setText("Buscar por Nombres.");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        jRadioButton4.setText("Buscar por Apellido Paterno.");
        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton4ActionPerformed(evt);
            }
        });

        jRadioButton5.setText("Buscar por Apellido Materno.");
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        jRadioButton6.setText("Buscar por Estado Civil.");
        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });

        jRadioButton7.setText("Buscar por Fecha de Inscripción.");
        jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton7ActionPerformed(evt);
            }
        });

        jRadioButton8.setText("Buscar por Activos.");
        jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton8ActionPerformed(evt);
            }
        });

        jRadioButton9.setText("Buscar por No Activos.");
        jRadioButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton9ActionPerformed(evt);
            }
        });

        jRadioButton10.setText("Mostrar Datos");
        jRadioButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jRadioButton1)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton4)
                            .addComponent(jRadioButton5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton6)
                            .addComponent(jRadioButton7)
                            .addComponent(jRadioButton8)
                            .addComponent(jRadioButton9)
                            .addComponent(jRadioButton10)))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton3)
                    .addComponent(jRadioButton8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton4)
                    .addComponent(jRadioButton9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton5)
                    .addComponent(jRadioButton10)))
        );

        jLabel1.setText("Contenido:");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Buscar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cargar Datos para Modificacion");
        jButton2.setEnabled(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        jRadioButton1.setSelected(true);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(true);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(true);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(true);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton4ActionPerformed

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton5ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(true);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton5ActionPerformed

    private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton6ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(true);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton6ActionPerformed

    private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton7ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(true);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton7ActionPerformed

    private void jRadioButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton8ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(true);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton8ActionPerformed

    private void jRadioButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton9ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(true);
        jRadioButton10.setSelected(false);
    }//GEN-LAST:event_jRadioButton9ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            /*Si buscar por Id's esta seleccionado*/
            if (jRadioButton1.isSelected()) {
                buscarPorId();
            }

            /*Si buscar por Ci esta seleccionado*/
            if (jRadioButton2.isSelected()) {
                buscarPorCi();
            }

            /*Si buscar por Nombres esta seleccionado.*/
            if (jRadioButton3.isSelected()) {
                buscarPorNombres();
            }

            /*Si buscar por Apellido Paterno esta seleccionado*/
            if (jRadioButton4.isSelected()) {
                buscarPorApellidoPaterno();
            }

            /*Si buscar por Apellido Materno esta seleccionado*/
            if (jRadioButton5.isSelected()) {
                buscarPorApellidoMaterno();
            }

            /*Si buscar por Estado Civil esta seleccionado*/
            if (jRadioButton6.isSelected()) {
                buscarPorEstadoCivil();
            }

            /*Si buscar por Fecha de Inscripciojn*/
            if (jRadioButton7.isSelected()) {
                buscarPorFechaInscripcion();
            }
            /*Si buscar por Activos esta seleccionado*/
            if (jRadioButton8.isSelected()) {
                buscarPorActivos();
            }

            /*Si buscar por No Activos esta seleccionado.*/
            if (jRadioButton9.isSelected()) {
                buscarPorNoActivos();
            }

            /*Si mostrar tabla esta seleccionado*/
            if (jRadioButton10.isSelected()) {
                mostrarDatos();
            }
        } catch (Exception error) {

            JOptionPane.showMessageDialog(this, error.getMessage(), "Búsqueda Afiliado", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jRadioButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton10ActionPerformed
        jRadioButton1.setSelected(false);
        jRadioButton2.setSelected(false);
        jRadioButton3.setSelected(false);
        jRadioButton4.setSelected(false);
        jRadioButton5.setSelected(false);
        jRadioButton6.setSelected(false);
        jRadioButton7.setSelected(false);
        jRadioButton8.setSelected(false);
        jRadioButton9.setSelected(false);
        jRadioButton10.setSelected(true);
    }//GEN-LAST:event_jRadioButton10ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        if (jTable1.getSelectedRow() != -1) {
            jButton2.setEnabled(true);
        } else {
            jButton2.setEnabled(false);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
        int index = jTable1.getSelectedRow();
        String v = (String)modelo.getValueAt(index, 0);
        VAfiliado.ID_AFILIADO =v;
        VAfiliado.MODIFICACION_ON = true;
        this.dispose();
        
    }//GEN-LAST:event_jButton2ActionPerformed

    public static void main(String args[]) {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VAfiliadoBusqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VAfiliadoBusqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VAfiliadoBusqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VAfiliadoBusqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new VAfiliadoBusqueda().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton10;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JRadioButton jRadioButton8;
    private javax.swing.JRadioButton jRadioButton9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    private void buscarPorId() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorId(contenido);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorCi() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorCi(Integer.parseInt(contenido));
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorNombres() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorNombres(contenido);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorApellidoPaterno() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorApellidoPaterno(contenido);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorApellidoMaterno() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorApellidoMaterno(contenido);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorEstadoCivil() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String contenido = jTextField1.getText();
            ArrayList<Object> respuesta = referencia.buscarPorEstadoCivil(contenido);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorFechaInscripcion() throws Exception {
        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Especifique algún contenido para la busqueda", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        } else {
            Date fecha = new Date(Date.parse(jTextField1.getText()));
            ArrayList<Object> respuesta = referencia.buscarPorFechaInscripcion(fecha);
            if (respuesta.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
                jTable1.setModel(new DefaultTableModel());
            } else {
                jTable1.setModel(referencia.tabularDatos(respuesta));
            }
        }
    }

    private void buscarPorActivos() throws Exception {
        ArrayList<Object> respuesta = referencia.buscarPorActivos();
        if (respuesta.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
            jTable1.setModel(new DefaultTableModel());
        } else {
            jTable1.setModel(referencia.tabularDatos(respuesta));
        }
    }

    private void buscarPorNoActivos() throws Exception {
        ArrayList<Object> respuesta = referencia.buscarPorNoActivos();
        if (respuesta.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
            jTable1.setModel(new DefaultTableModel());
        } else {
            jTable1.setModel(referencia.tabularDatos(respuesta));
        }
    }

    private void mostrarDatos() throws Exception {
        ArrayList<Object> respuesta = referencia.mostrarDatos();
        if (respuesta.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Búsqueda realizada, sin resultados", "Búsqueda Afiliado", JOptionPane.INFORMATION_MESSAGE);
            jTable1.setModel(new DefaultTableModel());
        } else {
            jTable1.setModel(referencia.tabularDatos(respuesta));
        }
    }
}